$(document).ready(function(){	
	$("#title").blur(validateTitle);
	$("#suibtitle").blur(validateSubTitle);
	$("#startvote").blur(validateStart);
	$("#maxvote").blur(validateMax);
	
	$("#title").keyup(validateTitle);
	$("#suibtitle").keyup(validateSubTitle);
	$("#startvote").keyup(validateStart);
	$("#maxvote").keyup(validateMax);
	
	function validateTitle(){
		//if it's NOT valid
		if($("#title").val().length < 4){
			$("#title").removeClass("inp-form");
			$("#title").addClass("inp-form-error");
			$("#titleInfo").text("The Title must more than 3 letters !");
			$("#titleInfo").addClass("error");
			hasError = false;
		}
		//if it's valid
		else{
			$("#title").addClass("inp-form");
			$("#title").removeClass("inp-form-error");
			$("#titleInfo").removeClass("error");
			$("#titleInfo").text("");
			hasError = true;
		}
	}
	function validateSubTitle(){
		//if it's NOT valid
		if($("#suibtitle").val().length < 4){
			$("#suibtitle").removeClass("inp-form");
			$("#suibtitle").addClass("inp-form-error");
			$("#subtitleInfor").text("The Sub Title must more than 3 letters !");
			$("#subtitleInfor").addClass("error");
			hasError = false;
		}
		//if it's valid
		else{
			$("#suibtitle").addClass("inp-form");
			$("#suibtitle").removeClass("inp-form-error");
			$("#subtitleInfor").removeClass("error");
			$("#subtitleInfor").text("");
			hasError = true;
		}
	}
	function validateStart(){
		var startReg = /[0-9]/;
		var startVal = $("#startvote").val();
		if(!startReg.test(startVal) || $("#startvote").val().length >= 5) {
			$("#startvote").removeClass("inp-form");
			$("#startvote").addClass("inp-form-error");
			$("#startvoteInfo").text("The start Vote must number and less than 4 digit !");
			$("#startvoteInfo").addClass("error");
			hasError = false;
		}
		//if it's valid
		else{
			$("#startvote").addClass("inp-form");
			$("#startvote").removeClass("inp-form-error");
			$("#startvoteInfo").removeClass("error");
			$("#startvoteInfo").text("");
			hasError = true;
		}
	}
	function validateMax(){
		var maxReg = /[0-9]/;
		var maxVal = $("#maxvote").val();
		if(!maxReg.test(maxVal) || $("#maxvote").val().length >= 6) {
			$("#maxvote").removeClass("inp-form");
			$("#maxvote").addClass("inp-form-error");
			$("#maxvoteInfo").text("The max Vote must number and less than 5 digit !");
			$("#maxvoteInfo").addClass("error");
			hasError = false;
		}
		//if it's valid
		else{
			$("#maxvote").addClass("inp-form");
			$("#maxvote").removeClass("inp-form-error");
			$("#maxvoteInfo").removeClass("error");
			$("#maxvoteInfo").text("");
			hasError = true;
		}
	}
});